import axios from 'axios'
// import qs from 'qs'

const domain = 'http://39.105.44.178'

export const getOrderList = (data = { page: 1, size: 30 }) => {

    // const data = { page, size }
    data = clean(data)
    const options = {
        method: 'POST',
        // headers: { 'content-type': 'application/x-www-form-urlencoded' },
        // data: qs.stringify(data),
        data,
        url: `${domain}/ark-manager/manage/orderList`,
    }
    return axios(options)
        .then(function(res) {
            return res.data
        })
        .then(commonHandle)
        .catch(function(error) {
            console.log(error)
            let temp = { "msg": "success", "code": "800", "data": { "result": { "count": "66", "list": [{ "buyerMsg": "", "createStr": "2018-07-01", "created": "2018-07-01 09:37:35", "delays": [], "id": "1601", "initialOrderDay": "22", "isRenew": "2", "orderStartSendDate": "2018-07-02 09:37:40", "orderType": "1", "orderValidStatus": "1", "payTime": "2018-07-01 09:37:40", "payment": "24900", "productName": "水果餐包月配送 · 优享餐（每天13.5元）", "productPrice": "29900", "productSku": "0000011", "receiverAddress": "新浪总部大厦收发室", "receiverMobile": "18410903248", "receiverName": "张先生", "renewLaterDay": "22", "renewOrderParentId": "0", "shippingType": "fetch", "status": "", "tid": "E20180701093735002300003", "tradeMsg": "", "updateDate": null, "userId": "oVVo000R5fpuYW5sCxZOyYCddxsA", "userNickname": "夜阳", "youzanStatus": "" }, { "buyerMsg": "", "createStr": "2018-07-01", "created": "2018-07-01 15:04:40", "delays": [], "id": "1600", "initialOrderDay": "22", "isRenew": "2", "orderStartSendDate": "2018-07-02 15:04:52", "orderType": "1", "orderValidStatus": "1", "payTime": "2018-07-01 15:04:52", "payment": "100", "productName": "水果餐包月配送 · 优享餐（每天13.5元）", "productPrice": "1800", "productSku": "0000012", "receiverAddress": "新浪总部大厦收发室", "receiverMobile": "13811345716", "receiverName": "张泽洲", "renewLaterDay": "22", "renewOrderParentId": "0", "shippingType": "fetch", "status": "", "tid": "E20180701150440046800002", "tradeMsg": "", "updateDate": null, "userId": "oVVo001W0ZbXWe48nIz14murAEV0", "userNickname": "张泽洲", "youzanStatus": "" }] }, "condition": { "currentDate": "2018-07-21 14:23:49", "endDate": null, "index": "0", "isRenew": "2", "orderBy": "0", "orderId": "0", "orderStatus": "WAIT_BUYER_PAY", "orderType": "0", "orderValidStatus": "1", "page": "1", "productName": "", "receiverAddress": "", "receiverMobile": "", "size": "2", "startDate": null, "userId": "", "userNickName": "" } } }
            return temp.data
        })
}

function commonHandle(res) {
    if (res.status == 800) return res.data
    else {
        __CLIENT__ && alert(res.msg)
    }
    return null
}

function clean(data) {
    const _data = {}
    for (let key in data) {
        if (data[key] !== '')
            _data[key] = data[key]
    }
    return _data
}